package com.example.enterprisemanager.mvvm.fragment.manager;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;

import com.example.enterprisemanager.BR;
import com.example.enterprisemanager.R;
import com.example.enterprisemanager.base.BaseBackFragment;
import com.example.enterprisemanager.databinding.FragmentEnrollBinding;
import com.example.enterprisemanager.mvvm.fragment.manager.dialog.MyDialogInput;
import com.example.enterprisemanager.mvvm.fragment.manager.dialog.OnDialogGetContext;

/**
 * A simple {@link Fragment} subclass.
 */
public class EnrollFragment extends BaseBackFragment<FragmentEnrollBinding, EnrollViewModel> {


    public static EnrollFragment newInstance() {
        return new EnrollFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_enroll;
    }

    @Override
    protected Class<EnrollViewModel> getModelClass() {
        return EnrollViewModel.class;
    }

    @Override
    protected int getVariableId() {
        return BR.viewModel;
    }

    @Override
    protected void initView() {
        super.initView();
        mBinding.toolbar.setTitle(R.string.str_enroll_manager);
        initToolbarNav(mBinding.toolbar);

        mBinding.rvEnrollGoods.setLayoutManager(new LinearLayoutManager(_mActivity));
        mBinding.rvEnrollGoods.setAdapter(mViewModel.adapter);
    }

    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {
        mViewModel.sendEnroll.observe(this, (sendEnroll) -> {

            new MyDialogInput().show(getString(R.string.str_enroll_manager), new OnDialogGetContext() {
                @Override
                public void getEditContext(String num) {

                    mViewModel.haveEnroll(sendEnroll,Integer.parseInt(num));

                }
            }, _mActivity.getSupportFragmentManager());

        });
    }

}
